package cn.uexpo.lhz.biz.impl;

import java.util.List;

import cn.uexpo.lhz.domain.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



import cn.uexpo.lhz.biz.ManyBiz;
import cn.uexpo.lhz.common.oldBase.BOException;
import cn.uexpo.lhz.common.oldUtils.PageRequest;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.common.oldUtils.PageUtils;
import cn.uexpo.lhz.dao.ManyMapper;
import cn.uexpo.lhz.domain.Many;

@Service
public class ManyBizImpl implements ManyBiz {

	@Autowired
	private ManyMapper manyMapper;

	@Override
	public int insert(Many record) throws BOException {
		return manyMapper.insert(record);
	}

	@Override
	public int insertSelective(Many record) throws BOException {
		return manyMapper.deleteByPrimaryKey(record.getId());

	}

	@Override
	public int deleteByPrimaryKey(Integer id) throws BOException {
		return manyMapper.deleteByPrimaryKey(id);

	}

	@Override
	public int deleteEntity(Many record) throws BOException {
		return manyMapper.deleteByPrimaryKey(record.getId());

	}

	@Override
	public int deleteByIds(List<Integer> ids) throws BOException {
		int no=0;
		if (null!=ids) {
			for (Integer id : ids) {
				no=manyMapper.deleteByPrimaryKey(id);
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int delete(List<Many> records) throws BOException {
		int no=0;
		if (null!=records&&records.size()>0){
			for (Many manyEntity : records) {
				no=manyMapper.deleteByPrimaryKey(manyEntity.getId());
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int deleteByExample(ManyExample example) throws BOException {
		return manyMapper.deleteByExample(example);

	}

	@Override
	public int updateByPrimaryKey(Many record) throws BOException {
		return manyMapper.updateByPrimaryKey(record);

	}

	@Override
	public int updateByPrimaryKeySelective(Many record) throws BOException {
		return manyMapper.updateByPrimaryKeySelective(record);

	}

	@Override
	public int updateByExampleSelective(Many record, ManyExample example) throws BOException {
		return manyMapper.updateByExampleSelective(record, example);

	}

	@Override
	public int updateByExample(Many record, ManyExample example) throws BOException {
		return manyMapper.updateByExample(record, example);

	}

	@Override
	public Many selectByPrimaryKey(Integer id) throws BOException {
		return manyMapper.selectByPrimaryKey(id);

	}

	@Override
	public Many selectByUniqueCode(String uniqueCode) throws BOException {
		return null;

	}

	@Override
	public List<Many> selectByExample(ManyExample example) throws BOException {
		return manyMapper.selectByExample(example);
	}

	@Override
	public long countByExample(ManyExample example) throws BOException {
		return manyMapper.countByExample(example);
	}

	@Override
	public PageResult findPage(PageRequest pageRequest, ManyExample example) throws BOException {
		int pageNum = pageRequest.getPage();
		int pageSize = pageRequest.getLimit();
		PageHelper.startPage(pageNum, pageSize);
		List<Many> records = (List<Many>) manyMapper.selectByExample(example);
		return PageUtils.getPageResult(pageRequest, new PageInfo<Many>(records));

	}

	//

	@Override
	public List<Many2Vo> selectByMany() {
		return manyMapper.selectByMany();
	}

	@Override
	public PageResult findPageMany(PageRequest pageRequest) throws BOException {
		int pageNum = pageRequest.getPage();
		int pageSize = pageRequest.getLimit();
		PageHelper.startPage(pageNum, pageSize);
		List<Many2Vo> records = (List<Many2Vo>) manyMapper.selectByMany();
		return PageUtils.getPageResult(pageRequest, new PageInfo<Many2Vo>(records));
	}

	@Override
	public List<Many3Vo> selectByAll() {
		return manyMapper.selectByAll();
	}

	@Override
	public List<Many2Vo> listShow(Many2Vo many2Vo) {
		List<Many2Vo> list = manyMapper.listShow(many2Vo);
		return list;
	}

	@Override
	public PageResult findPage1(PageRequest pageRequest, Many2Vo many2Vo) throws BOException {
		int pageNum = pageRequest.getPage();
		int pageSize = pageRequest.getLimit();
		PageHelper.startPage(pageNum, pageSize);
		List<Many2Vo> records = manyMapper.listShow(many2Vo);
		return PageUtils.getPageResult(pageRequest, new PageInfo<Many2Vo>(records));
	}


}
